#搜索
from selenium import webdriver #引入
import time
from selenium.webdriver.common.by import By #引入By类
from selenium.webdriver.common.action_chains import ActionChains  #引入类
driver = webdriver.Chrome() #实例化
driver.get('http://192.168.4.138/ecshop/user.php') #访问ECSHOP
driver.maximize_window()  # 最大化窗口

#登录
driver.implicitly_wait(30)
driver.find_element(By.NAME,"username").send_keys("李秀")
driver.find_element(By.NAME,"password").send_keys("123456")
driver.find_element(By.NAME,"submit").click()

#关键词搜索商品
driver.find_element(By.NAME,"keywords").send_keys("BMW M4")  #输入名称
driver.find_element(By.NAME,'imageField').click()         #点击搜索

#页面点击搜索商品
driver.find_element(By.XPATH,'/html/body/div[4]/div/div/a[1]').click()
driver.find_element(By.XPATH,'//div[@id="HandleLI2_2"]/a').click()

#页面鼠标悬浮查找商品
driver.find_element(By.XPATH,'/html/body/div[4]/div/div/a[1]').click()
locator = driver.find_element_by_xpath('////div[@id="HandleLI2_1"]/a"]')#定位男装
time.sleep(2)
action = ActionChains(driver)#实例化
action.move_to_element(locator).perform()#让鼠标悬停
driver.find_element_by_link_text('裤子').click()